//
//  AddFamilyCallViewController.m
//  Cunli
//
//  Created by 湛亚 on 15/8/4.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "AddFamilyCallViewController.h"
#import "TongXunLuViewController.h"
#import "MyDataService.h"
#import "NSString+MD5.h"
#import "PersonInfo.h"
#import "PhoneNameTableViewCell.h"
//#import "UIImageView+WebCache.h"
#import "PeopleDataViewController.h"
#import "MJRefresh.h"
#import "FamilyCallViewController.h"
#import "FamilyInfo.h"
#import "LMComBoxView.h"
#import "TongXunLuTableViewCell.h"
//#import "SDImageCache.h"
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"

@interface AddFamilyCallViewController ()<UISearchBarDelegate,LMComBoxViewDelegate>{
    
    NSMutableArray *tongXunLuArray,*searchArray,*ziMuArray,*sectionArray,*tableViewArray,*searchSection,*personArray;
    BOOL isSearch;
    NSString  *currentZiMu,*currentSearchZiMu,*currentSearchCondition;
    UITableView *shouZiMuTableView;
    float screenWidth,screenHeight;
    int sectionCount,refreshPage,searchPage,searchSectionCount;
    MBProgressHUD *hudFirst;
    NSMutableDictionary *chooseFamilyDic;
    PersonInfo *cellPerson;
    LMComBoxView *mlmBox;
}

@end

@implementation AddFamilyCallViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    screenWidth=[UIScreen mainScreen].bounds.size.width;
    screenHeight=[UIScreen mainScreen].bounds.size.height;
    
    [self createChooseButton];
    
    isSearch=NO;
    chooseFamilyDic=[[NSMutableDictionary alloc]init];
    
    _nameSearchBar=[[UISearchBar alloc]init];
    _nameSearchBar.frame=CGRectMake(0, 0, screenWidth, 44);
    _nameSearchBar.delegate=self;
    _nameSearchBar.placeholder=@"搜索";
    [self.view addSubview:_nameSearchBar];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 28, 28);
    [leftBtn setImage:[UIImage imageNamed:@"regback01"] forState:UIControlStateNormal];
    leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    
    self.AddCallTableView.rowHeight=50;
    [self createSearchContion];
    if (!self.orTongXunLu) {
        
        self.title=@"添加亲人";
        [self creareNavButton];
        self.AddCallTableView.editing=YES;
    }else{
        self.title=self.personType;
        //[self createSearchContion];
    }
    
}

//设置搜索条件按钮
-(void)createSearchContion{
    
    _nameSearchBar.frame=CGRectMake(66, 5, screenWidth-76, 34);
    _nameSearchBar.backgroundImage=[UIImage imageNamed:@"white.png"];
    [_nameSearchBar.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    [_nameSearchBar.layer setBorderWidth:1.0];
    _nameSearchBar.layer.cornerRadius = 5;
    _nameSearchBar.clipsToBounds = YES;
    
    mlmBox = [[LMComBoxView alloc] initWithFrame:CGRectMake(10, 5, 60, 34)];
    mlmBox.backgroundColor = [UIColor whiteColor];
    mlmBox.titlesList = [NSMutableArray arrayWithObjects:@"姓名", @"地区", nil];
    mlmBox.btnBgImgStr = @"searchLeft.png";
    mlmBox.delegate = self;
    mlmBox.supView = self.view;
    [mlmBox defaultSettings];
    [self.view addSubview:mlmBox];
}

-(void)selectAtIndex:(int)index inCombox:(LMComBoxView *)_combox
{
    NSLog(@"index:%d, title:%@", index, _combox.titlesList[index]);
    currentSearchCondition=_combox.titlesList[index];
}

-(void)creareNavButton{
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 65, 30);
    [rightBtn setTitle:@"确定" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(chooseFamilyCall) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    
    UIBarButtonItem *flexSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    flexSpacer.width = flexSpacer.width - 20;
    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:flexSpacer, rightBarItem, nil]];
    
}

-(void)createChooseButton{
    
    ziMuArray=[[NSMutableArray alloc]initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z", nil];
    
    float hight=(screenHeight-108)/26;
    for (int i=0; i<26; i++) {
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=CGRectMake(screenWidth-25, 44+i*hight, 25, hight);
        [btn setTitle:[ziMuArray objectAtIndex:i] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(goToSection:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag=i;
        [btn.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.view addSubview:btn];
    }
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    if (self.orRefresh) {
        
        sectionCount=-1;
        searchSectionCount=-1;
        tongXunLuArray=[[NSMutableArray alloc]init];
        
        searchArray=[[NSMutableArray alloc]init];
        sectionArray=[[NSMutableArray alloc]init];
        
        tableViewArray=[[NSMutableArray alloc]init];
        searchSection=[[NSMutableArray alloc]init];
        //personArray=[[NSMutableArray alloc]init];
        [self getTongXunLuInfo];
        self.orRefresh=NO;
    }
}

-(void)chooseFamilyCall{
    
    if (chooseFamilyDic.count==0) {
        
        [self showAlertWithMessage:@"请选择亲人!"];
        return;
    }else{
        
        int i=0;
        NSString *userIdString=nil;
        for (NSString *userId in [chooseFamilyDic allValues]) {
            NSLog(@"value: %@", userId);
            
            if (i>0) {
                userIdString=[NSString stringWithFormat:@"%@,%@",userIdString,userId];
            }else{
                userIdString=[NSString stringWithFormat:@"%@",userId];
            }
            i=i+1;
        }
        //NSLog(@"亲人userid：%@",userIdString);
        [self sendFamilyUseridsWithString:userIdString];
    }
}

-(void)sendFamilyUseridsWithString:(NSString *)userids{
    
    hudFirst = [Config createHUD];
    hudFirst.mode = 0;
    hudFirst.userInteractionEnabled=NO;
    hudFirst.labelText = @"添加中...";
    
    NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:userids forKey:@"m_userids"];
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    [MyDataService requestURL:@"add_own_relative.php" httpMethod:@"POST" params:CheckParams fileDatas:nil complection:^(id result) {
        
        [hudFirst hide:YES];
        NSLog(@"%@",result);
        
        if ([[result objectForKey:@"response"] isEqualToString:@"add_own_relative"]) {
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
            hud.labelText = @"添加亲人成功";
            [hud hide:YES afterDelay:1];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"orSendRequest1" object:@YES];
            [self.navigationController popViewControllerAnimated:YES];
            
        }else{
            
            NSString *errorString=[[result objectForKey:@"error"] objectForKey:@"text"];
            [self showAlertWithMessage:errorString];
            isSearch=NO;
            [chooseFamilyDic removeAllObjects];
            [self.AddCallTableView reloadData];
        }
        
    }failureAction:^{
        [hudFirst hide:YES];
        [self showAlertWithMessage:@"网络错误,添加失败!"];
    }];
    
}

//跳转到指定区
-(void)goToSection:(UIButton *)btn{
    
    [self.view endEditing:YES];
    NSString *ziMuString=[ziMuArray objectAtIndex:btn.tag];
    
    if (isSearch) {
        for (int i=0; i<searchSection.count; i++) {
            
            if ([ziMuString isEqualToString:[searchSection objectAtIndex:i]]) {
                
                NSIndexPath*indexPath =[NSIndexPath indexPathForRow:0 inSection:i];
                //单元格滚到指定的位置
                [self.AddCallTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
                
                return;
            }
        }
    }else{
        
        for (int i=0; i<sectionArray.count; i++) {
            
            if ([ziMuString isEqualToString:[sectionArray objectAtIndex:i]]) {
                
                NSIndexPath*indexPath =[NSIndexPath indexPathForRow:0 inSection:i];
                //单元格滚到指定的位置
                [self.AddCallTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
                
                return;
            }
        }
        
    }
    
}

//点击search按钮开始搜索
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    
    [self.view endEditing:YES];
    
    //    [searchArray removeAllObjects];
    //    [searchSection removeAllObjects];
    //    currentSearchZiMu=nil;
    //    searchSectionCount=-1;
    
    //如果是通讯录，并且数组无内容
    if (tableViewArray.count==0) {
        MBProgressHUD *hud = [Config createHUD];
        hud.mode = MBProgressHUDModeCustomView;
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
        hud.labelText = @"无搜索结果";
        [hud hide:YES afterDelay:1];
        return ;
    }
    
    [self getSearchWithString:searchBar.text];
}
//搜索
-(void)getSearchWithString:(NSString *)str{
    
    NSMutableArray *areaSearchArray=[[NSMutableArray alloc]init];
    
    if ([currentSearchCondition isEqualToString:@"地区"]) {
        
        for (NSMutableArray *arr in tableViewArray) {
            for (PersonInfo *person in arr) {
                NSRange foundObj=[person.all_workareaname rangeOfString:str options:NSCaseInsensitiveSearch];
                if(foundObj.length>0) {
                    [areaSearchArray addObject:person];
                }
            }
        }
    }else{
        
        for (NSMutableArray *arr in tableViewArray) {
            for (PersonInfo *person in arr) {
                NSRange foundObj=[person.truename rangeOfString:str options:NSCaseInsensitiveSearch];
                if(foundObj.length>0) {
                    [areaSearchArray addObject:person];
                }
            }
        }
    }
    //无搜索结果
    if (areaSearchArray.count<1) {
        MBProgressHUD *hud = [Config createHUD];
        hud.mode = MBProgressHUDModeCustomView;
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
        hud.labelText = @"无搜索结果";
        [hud hide:YES afterDelay:1];
        return;
    }else{
        
        [chooseFamilyDic removeAllObjects];
        [searchArray removeAllObjects];
        [searchSection removeAllObjects];
        currentSearchZiMu=nil;
        searchSectionCount=-1;
        
        for (PersonInfo *person in areaSearchArray) {
            //判断首字母和当前区字母是否一致
            if ([person.group isEqualToString:currentSearchZiMu]) {
                [[searchArray objectAtIndex:searchSectionCount] addObject:person];
            }else{
                
                for (int i=0; i<ziMuArray.count; i++) {
                    
                    if ([person.group isEqualToString:[ziMuArray objectAtIndex:i]]) {
                        
                        NSMutableArray *secArray=[[NSMutableArray alloc]init];
                        [secArray addObject:person];
                        [searchArray addObject:secArray];
                        searchSectionCount=searchSectionCount+1;
                        currentSearchZiMu=person.group;
                        [searchSection addObject:person.group];
                        break;
                    }
                }
                
            }
            
        }
        isSearch=YES;
        [self.AddCallTableView reloadData];
    }
}

//搜索框值变化时执行
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
    
    if ([searchBar.text isEqualToString:@""]) {
        isSearch=NO;
        currentSearchZiMu=nil;
        [self.view endEditing:YES];
        [chooseFamilyDic removeAllObjects];
        [self.AddCallTableView reloadData];
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (mlmBox.isOpen) {
        [mlmBox tapAction];
    }
    [self.view endEditing:YES];
}

- (void)showAlertWithMessage:(NSString *)message
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}

-(void)goBack{
    
    [hudFirst removeFromSuperview];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"orSendRequest" object:@YES];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)getTongXunLuInfo{
    
    NSUserDefaults *userdefaults=[NSUserDefaults standardUserDefaults];
    NSArray *listArray;
    //显示通讯录
    if (self.orTongXunLu) {
        //            if ([self.personType isEqualToString:@"本村人"]) {
        //                listArray=[userdefaults objectForKey:@"benCunArray"];
        //            }else{
        //                listArray=[userdefaults objectForKey:@"jiaXiangArray"];
        //            }
        [self getAddressBook];
        return;
    }else{
        //所有人
        listArray=[userdefaults objectForKey:@"tongXunLuArray"];
    }
    
    if (listArray.count==0) {
        
        MBProgressHUD *hud = [Config createHUD];
        hud.mode = MBProgressHUDModeCustomView;
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
        hud.labelText = @"没有更多数据";
        [hud hide:YES afterDelay:1];
        return ;
    }
    
    for (NSDictionary *dic in listArray) {
        
        //PersonInfo *person=[[PersonInfo alloc]initWithDictionary:dic];
        PersonInfo *person=[PersonInfo yy_modelWithDictionary:dic];
        //如果是自己直接跳出
        if (person.userid==[[Config getOwnUserID] intValue]) {
            continue;
        }
        BOOL orFamilly=NO;
        //判断是否已在亲人列表
        for (FamilyInfo *family in self.familyArr) {
            if (person.userid==[family.userid intValue]) {
                
                orFamilly=YES;
                break;
            }
        }
        
        if (orFamilly) {
            continue;
        }
        
        if ([person.group isEqualToString:currentZiMu]) {
            [[tableViewArray objectAtIndex:sectionCount] addObject:person];
        }else{
            
            for (int i=0; i<ziMuArray.count; i++) {
                
                if ([person.group isEqualToString:[ziMuArray objectAtIndex:i]]) {
                    
                    NSMutableArray *secArray=[[NSMutableArray alloc]init];
                    [secArray addObject:person];
                    [tableViewArray addObject:secArray];
                    sectionCount=sectionCount+1;
                    currentZiMu=person.group;
                    [sectionArray addObject:person.group];
                    break;
                }
            }
            
        }
        
    }
    [self.AddCallTableView reloadData];
}

-(void)createTableViewDataWithArray:(NSArray *)arr{
    
    for (NSDictionary *dic in arr) {
        
        //PersonInfo *person=[[PersonInfo alloc]initWithDictionary:dic];
        PersonInfo *person=[PersonInfo yy_modelWithDictionary:dic];
        if ([person.group isEqualToString:currentZiMu]) {
            [[tableViewArray objectAtIndex:sectionCount] addObject:person];
        }else{
            
            for (int i=0; i<ziMuArray.count; i++) {
                
                if ([person.group isEqualToString:[ziMuArray objectAtIndex:i]]) {
                    
                    NSMutableArray *secArray=[[NSMutableArray alloc]init];
                    [secArray addObject:person];
                    [tableViewArray addObject:secArray];
                    sectionCount=sectionCount+1;
                    currentZiMu=person.group;
                    [sectionArray addObject:person.group];
                    break;
                }
            }
            
        }
        //[personArray addObject:person];
    }
    //加载添加新数据的表
    [self.AddCallTableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (isSearch) {
        return [[searchArray objectAtIndex:section] count];
    }
    return [[tableViewArray objectAtIndex:section] count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (isSearch) {
        return searchArray.count;
    }
    return tableViewArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    PhoneNameTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"phonename"];
    //
    //    if(!cell){
    //
    //        cell = [[[NSBundle mainBundle] loadNibNamed:@"PhoneNameTableViewCell" owner:nil options:nil] lastObject];
    //    }
    
    static NSString *cellIdentifier=@"name";
    BOOL nibsRegistered=NO;
    if (!nibsRegistered) {
        UINib *nib=[UINib nibWithNibName:@"PhoneNameTableViewCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
        nibsRegistered=YES;
    }
    PhoneNameTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (isSearch) {
        cellPerson=[[searchArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    }else{
        cellPerson=[[tableViewArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    }
    
    cell.phoneImg.image=[UIImage imageNamed:@"default_touxiang"];
    cell.phoneImg.layer.cornerRadius = 20;
    cell.phoneImg.clipsToBounds = YES;
    cell.phoneNameLab.text=cellPerson.truename;
    cell.workArealabel.text=cellPerson.workareaname;
    return cell;
}

- (void)loadImagesForOnscreenRows
{
    
    //获取tableview正在window上显示的cell，加载这些cell上图像。通过indexPath可以获取该行上需要展示的cell对象
    NSArray * visibleCells = [self.AddCallTableView indexPathsForVisibleRows];
    for (NSIndexPath * indexPath in visibleCells) {
        if (isSearch) {
            cellPerson=[[searchArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        }else{
            cellPerson=[[tableViewArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        }
        NSRange foundObj=[cellPerson.pic rangeOfString:@"default_touxiao.png" options:NSCaseInsensitiveSearch];
        if(!foundObj.length>0) {
            PhoneNameTableViewCell * cell = (PhoneNameTableViewCell *)[self.AddCallTableView cellForRowAtIndexPath:indexPath];
            [cell.phoneImg setImageWithURL:[NSURL URLWithString:cellPerson.pic]];
        }
        
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //如果tableview停止滚动，开始加载图像
    [self loadImagesForOnscreenRows];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (mlmBox.isOpen) {
        [mlmBox tapAction];
    }
    
    [self.view endEditing:YES];
    
    PersonInfo *person;
    if (isSearch) {
        person=[[searchArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    }else{
        person=[[tableViewArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    }
    
    if (self.orTongXunLu) {
        //进入个人详情
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
        PeopleDataViewController *peopleVC=[[PeopleDataViewController alloc]init];
        peopleVC.touserid=[NSString stringWithFormat:@"%d",person.userid];
        [self.navigationController pushViewController:peopleVC animated:YES];
        return;
    }
    //把选中的人保存进入字典
    [chooseFamilyDic setObject:[NSString stringWithFormat:@"%d",person.userid] forKey:[NSString stringWithFormat:@"%ld%ld",indexPath.section,indexPath.row]];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
    if (isSearch) {
        return [searchSection objectAtIndex:section];
    }
    return [sectionArray objectAtIndex:section];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 25;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

//取消选择
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //移除选中的人
    [chooseFamilyDic removeObjectForKey:[NSString stringWithFormat:@"%ld%ld",indexPath.section,indexPath.row]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [[SDImageCache sharedImageCache] clearMemory];
}

#pragma mark -获取通讯录数据

-(void)getAddressBook{
    
    hudFirst = [Config createHUD];
    hudFirst.mode = 0;
    hudFirst.labelText = @"获取信息中...";
    hudFirst.userInteractionEnabled=NO;
    
    NSMutableDictionary *CheckParams =[[NSMutableDictionary alloc]init];
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:self.areaid forKey:@"areaids"];
    [CheckParams setObject:self.mark forKey:@"mark"];
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    [MyDataService requestURL:@"addressbook_gper.php" httpMethod:@"GET" params:CheckParams fileDatas:nil complection:^(id result) {
        
        NSLog(@"#########%@",result);
        [hudFirst hide:YES];
        
        if ([[result objectForKey:@"response"] isEqualToString:@"addressbook_gper"]) {
            
            NSDictionary *dataDic=[result objectForKey:@"data"];
            NSArray *addressArray=[dataDic objectForKey:@"list"];
            
            if (addressArray.count<1) {
                
                MBProgressHUD *hud = [Config createHUD];
                hud.mode = MBProgressHUDModeCustomView;
                hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"done"]];
                hud.labelText = @"没有更多数据";
                [hud hide:YES afterDelay:1];
                return ;
            }else{
                
                [self createTableViewDataWithArray:addressArray];
            }
            
        }else{
            
            MBProgressHUD *hud = [Config createHUD];
            hud.mode = MBProgressHUDModeCustomView;
            hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
            hud.labelText = @"获取数据失败!";
            [hud hide:YES afterDelay:1];
        }
        
    }failureAction:^{
        
    }];
    
}

@end
